﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Text;
using System.Net;

using LRSTaxServices.Biz;

public partial class TaxFeesSuccess : System.Web.UI.Page
{
    #region Constants

    private const string PROP_DATASRC_DEBITTRANSACTIONS = "__DebitTransactions::DT";
    private const string PROP_DATASRC_CREDITTRANSACTIONS = "__CreditTransactions::DT";

    private const string PROP_DATASRC_LRSDEBITTRANSACTIONS = "__LRSDebitTransactions::LRSDT";
    private const string PROP_DATASRC_LRSCREDITTRANSACTIONS = "__LRSCreditTransactions::LRSDT";

    #endregion

    #region Public Properties

    public UserTransactionsCollection DataSourceUsersDebitTransactions
    {
        get { return (SessionMgr.Session[PROP_DATASRC_DEBITTRANSACTIONS] is UserTransactionsCollection ? (UserTransactionsCollection)SessionMgr.Session[PROP_DATASRC_DEBITTRANSACTIONS] : (UserTransactionsCollection)(SessionMgr.Session[PROP_DATASRC_DEBITTRANSACTIONS] = new UserTransactionsCollection())); }
        set { SessionMgr.Session[PROP_DATASRC_DEBITTRANSACTIONS] = value; }
    }

    public UserTransactionsCollection DataSourceUsersCreditTransactions
    {
        get { return (SessionMgr.Session[PROP_DATASRC_CREDITTRANSACTIONS] is UserTransactionsCollection ? (UserTransactionsCollection)SessionMgr.Session[PROP_DATASRC_CREDITTRANSACTIONS] : (UserTransactionsCollection)(SessionMgr.Session[PROP_DATASRC_CREDITTRANSACTIONS] = new UserTransactionsCollection())); }
        set { SessionMgr.Session[PROP_DATASRC_CREDITTRANSACTIONS] = value; }
    }

    public LRSTransactionsCollection DataSourceLRSDebitTransactions
    {
        get { return (SessionMgr.Session[PROP_DATASRC_LRSDEBITTRANSACTIONS] is LRSTransactionsCollection ? (LRSTransactionsCollection)SessionMgr.Session[PROP_DATASRC_LRSDEBITTRANSACTIONS] : (LRSTransactionsCollection)(SessionMgr.Session[PROP_DATASRC_LRSDEBITTRANSACTIONS] = new LRSTransactionsCollection())); }
        set { SessionMgr.Session[PROP_DATASRC_LRSDEBITTRANSACTIONS] = value; }
    }

    public LRSTransactionsCollection DataSourceLRSCreditTransactions
    {
        get { return (SessionMgr.Session[PROP_DATASRC_LRSCREDITTRANSACTIONS] is LRSTransactionsCollection ? (LRSTransactionsCollection)SessionMgr.Session[PROP_DATASRC_LRSCREDITTRANSACTIONS] : (LRSTransactionsCollection)(SessionMgr.Session[PROP_DATASRC_LRSCREDITTRANSACTIONS] = new LRSTransactionsCollection())); }
        set { SessionMgr.Session[PROP_DATASRC_LRSCREDITTRANSACTIONS] = value; }
    }

    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            
            DataSourceLRSDebitTransactions = LRSTransactions.GetAllTransactionsByUserIDnTransactionType("LRS", "Debit");
            DataSourceLRSCreditTransactions = LRSTransactions.GetAllTransactionsByUserIDnTransactionType("LRS", "Credit");            

            double LRStotaldebitedamount = 0;
            double LRStotalcreditedamount = 0;            

            for (int i = 0; i < DataSourceLRSDebitTransactions.Count; i++)
            {
                LRStotaldebitedamount = LRStotaldebitedamount + DataSourceLRSDebitTransactions[i].Amount;

            }

            for (int i = 0; i < DataSourceLRSCreditTransactions.Count; i++)
            {
                LRStotalcreditedamount = LRStotalcreditedamount + DataSourceLRSCreditTransactions[i].Amount;
            }


            //LRS Transactions DataBase Storage

            LRSTransactions LRStransactionObj = LRSTransactions.CreateNew();
            LRStransactionObj.TransactionDate = DateTime.Now;
            LRStransactionObj.UserID = "LRS";
            LRStransactionObj.RefID = Request.QueryString["tx"].ToString();
            LRStransactionObj.TransactionType = "Credit";
            LRStransactionObj.Description = "LRS Tax fees.";
            LRStransactionObj.Amount = double.Parse(Request.QueryString["amt"].ToString());
            LRStransactionObj.Balance = (LRStotalcreditedamount - LRStotaldebitedamount) + LRStransactionObj.Amount;
            LRSTransactions.Update(LRStransactionObj);

            //to do send an automated mail to admin..
            string emailfeedback;
            bool emailsend = LRSTaxServices.MailUtils.SendEmail("sachin.verma@vermasoftech.com", "admin", "Regarding Successfull tax fees submited by User", "A user has successfully submited tax fees.<br><br> This is an auto generated mail,please do not reply.", out emailfeedback);
            // update job 


            Response.AppendHeader("Refresh", "10; url=Default.aspx");
        }
    }

    #endregion

    #endregion
}
